using WatiNCF;
using WatiNCF.Extensions;
using WatiN.Core;

namespace Northwind.Watin.Controllers.Employees
{
    public class EmployeeDetailsController : PageController<EmployeeDetailsController>
    {
        public EmployeeDetailsController(IHomePageController homePage, IPageController parentPage) 
            : base(homePage, parentPage)
        {
        }

        public EmployeeController ChangeDetails(EmployeeDetails details)
        {
            Browser.TextField(ByPartialId("txtFirstname")).IfExists<TextField>(tf => tf.TypeText(details.FirstName));
            Browser.TextField(ByPartialId("txtLastname")).IfExists<TextField>(tf => tf.TypeText(details.LastName));
            Browser.SelectList(ByPartialId("ddReportsTo")).IfExists<SelectList>(tf => tf.Select(details.ReportsTo));
            Browser.Button(ByPartialId("btEdit")).Click();
            return GoToEmployees();
        }

        public EmployeeController GoToEmployees()
        {
            Browser.Link(Find.ByText("Employees")).Click();
            return ParentPage as EmployeeController;
        }
    }
}